<template>
	<view class="content">
		<uv-navbar title="纸上良宸"  :fixed="false" >
			<template slot="left"> 
				<view></view>
			</template>
		</uv-navbar>
	<!-- 	<view class="userInfo" @click="gotoinfo" :style="{top: top + 'px'}" v-if="top">
			<image v-if="userInfo.avatarUrl" :src="userInfo.avatarUrl" mode="aspectFit"></image>
			<image v-else src="../../static/user.png" mode="aspectFit"></image>
		</view> -->
		<view :style="{ 
			position: 'absolute', top: titH + 'px', left: 0, bottom: 0 + 'px'
		}">
			<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" class="swipercontent" >
				<swiper-item v-for="ele in banners" :key="ele">
					<view class="swiper-item" >
						<image :src="ele" mode="scaleToFill"></image>
					</view>
				</swiper-item>
			</swiper>
		</view>
	</view>
</template>

<script>
	import { getOpenId, userInfoAdd, getUserInfo, noticeList } from '@/api'
	import { extractImgSrc, downloadImage } from '@/utils/utils.js'
	import { baseRequst } from '@/utils/config.js' 
	export default {
		
		data() {
			const sysInfo = uni.getSystemInfoSync()
			return {
				titH:  sysInfo.statusBarHeight + 44,
				userInfo: {},
				top: 0,
				banners: [],
				title: 'Hello'
			}
		},
		mounted() {
			noticeList().then(d => {
				this.banners = d.rows.map(ele => baseRequst + extractImgSrc(ele.noticeContent))
			})
			const statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
			// 获取胶囊按钮的布局位置信息
			const custom = wx.getMenuButtonBoundingClientRect();
			// 计算标题栏高度
			const navigationBarHeight = custom.height + (custom.top - statusBarHeight) * 2;
			this.top = navigationBarHeight + statusBarHeight
			this.init()
		},
		methods: {
		 	async init() {
				const openidRes = await getOpenId().catch(err => {
					console.log('openidReserr', err)
				})	
				uni.setStorageSync('openid', openidRes.data.openid)
				const res = await wx.getUserInfo()
				await userInfoAdd({
						nickName: '微信用户',
						avatarUrl: await downloadImage(res.userInfo.avatarUrl),
						openid: openidRes.data.openid,
						parentInviteCode: uni.getStorageSync('inviteCode') || ''
					}) 
				const userRes = await getUserInfo()
				uni.setStorageSync('userinfo', JSON.stringify(userRes.data))
				// if(!userRes.data) {
				// 	const res = await wx.getUserInfo()
				// }else{
				// 	this.userInfo = userRes.data
				// 	uni.setStorageSync('userinfo', JSON.stringify(this.userInfo))
				// }
			},
			gotoinfo() {
				this.$emit('toUser')
			}
		}
	}
</script>

<style scoped lang="scss">
	$tabbarh: calc( 100vh - 83px );
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
	.userInfo {
		position: fixed;
		width: 100upx;
		height: 100upx;
		border-radius: 50%;
		// top: calc(var(--status-bar-height) + 64rpx) ;
		right: 20upx;
		z-index: 999;
		background-color: #fff;
		display: flex;
		justify-content: center; 
		align-items: center;
		overflow: hidden;
		image {
			width: 100%;
			height: 100%;
		}
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
	.swipercontent {
		position: absolute;
		width: 100vw;
		height: 100%;
		.swiper-item {
			width: 100vw;
			height: 100%;
			image {
				width: 100vw;
				height: 100%;
			}
		}
	}
</style>
